﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Hotel
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        public static string UserName = string.Empty;

        Reservations res = new Reservations();
        CheckReservation chkres = new CheckReservation();
        Checkin chkin = new Checkin();
        ServiceForRoom svfr = new ServiceForRoom();
        ChangeRoom chr = new ChangeRoom();
        Checkout chkout = new Checkout();

        CustomerManagement cm = new CustomerManagement();
        TypeRoom tr = new TypeRoom();
        Room rm = new Room();
        Service sv = new Service();

        Statistics st = new Statistics();
        ExpiredRoom epr = new ExpiredRoom();

        Profiles pf = new Profiles();
        Account ac = new Account();
        
        CNDatabase dt = new CNDatabase();

        private void hideAllForm()
        {
            res.Hide();
            chkres.Hide();
            chkin.Hide();
            svfr.Hide();
            chr.Hide();
            chkout.Hide();

            cm.Hide();
            tr.Hide();
            rm.Hide();
            sv.Hide();

            st.Hide();
            epr.Hide();

            pf.Hide();
            ac.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Profiles pf = new Profiles();
            pf.Location = new Point(200,40);
            pf.Show();
            
        }

        private void labelRole()
        {
            string role = dt.getOneData("SELECT [IDRole] FROM Account where IDAccount = '" + UserName + "'").ToString();
            if (role == "1")
            {
                LbRole.Text = " ( Role : Adminstrator )";
            }
            else
            {
                LbRole.Text = " ( Role : Staff )";
                pictureBox1.Visible = false;
                pictureBox2.Visible = true;
            }
        }

        private void Main_Load(object sender, EventArgs e)
        {
            //Session of Staff
            if (!string.IsNullOrEmpty(UserName))
                LbSESSION.Text = UserName;
            labelRole();
            epr.BringToFront();
        }

        private void BtReservation_Click(object sender, EventArgs e)
        {
            hideAllForm();
            res.Location = new Point(200, 40);
            res.Show();

        }

       

        private void BtCheckIn_Click(object sender, EventArgs e)
        {
            hideAllForm();
            chkin.Location = new Point(200, 40);
            chkin.Show();
        }

        private void pbClose_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to exit the application?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
                Application.Exit();
        }

        private void BtCheckReservation_Click(object sender, EventArgs e)
        {
            hideAllForm();
            chkres.Location = new Point(200, 40);
            chkres.Show();
        }

        private void BtSerForRoom_Click(object sender, EventArgs e)
        {
            hideAllForm();
            svfr.Location = new Point(200, 40);
            svfr.Show();
        }

        private void btCheckOut_Click(object sender, EventArgs e)
        {
            hideAllForm();
            chkout.Location = new Point(200, 40);
            chkout.Show();
        }

        private void btRoomChange_Click(object sender, EventArgs e)
        {
            hideAllForm();
            chr.Location = new Point(200, 40);
            chr.Show();
        }

        private void btDayExtend_Click(object sender, EventArgs e)
        {
            hideAllForm();
            chr.Location = new Point(200, 40);
            chr.Show();
        }

        private void btTypeRoom_Click(object sender, EventArgs e)
        {
            hideAllForm();
            tr.Location = new Point(200, 40);
            tr.Show();
        }

        private void btRoom_Click(object sender, EventArgs e)
        {
            hideAllForm();
            rm.Location = new Point(200, 40);
            rm.Show();
        }

        private void btService_Click(object sender, EventArgs e)
        {
            hideAllForm();
            sv.Location = new Point(200, 40);
            sv.Show();
        }

       private void btSearch_Click(object sender, EventArgs e)
        {
            hideAllForm();
            cm.Location = new Point(200, 40);
            cm.Show();
        }

        private void btStatistic_Click(object sender, EventArgs e)
        {
            hideAllForm();
            st.Location = new Point(200, 40);
            st.Show();
        }

        private void btCustomer_Click(object sender, EventArgs e)
        {
            hideAllForm();
            cm.Location = new Point(200, 40);
            cm.Show();
        }

        private void btNotice_Click(object sender, EventArgs e)
        {
            hideAllForm();
            epr.Location = new Point(200, 40);
            epr.Show();
            
        }

        private void btProfiles_Click(object sender, EventArgs e)
        {
            Profiles.UserName = UserName;
            hideAllForm();
            pf.Location = new Point(200, 40);
            pf.Show();
        }

        private void btAccount_Click(object sender, EventArgs e)
        {
            string RoleAD = dt.getOneData("SELECT [IDRole] FROM Account where IDAccount = '" + UserName + "'").ToString();
            if (RoleAD != "1")
                MessageBox.Show("You doesn't have permission to access this function!", "Access Denied....");
            else
            {
                hideAllForm();
                ac.Location = new Point(200, 40);
                ac.Show();
            }
        }

        private void btLogOut_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to exit the application?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
                Application.Exit();
        }

        

     
        
      
       

      

       

     

     

       

        


      }

    }

